@{
    ViewData["Title"] = "编辑入职审核";
    Layout = null;
    var onboardingData = ViewBag.OnboardingData;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑入职审核</title>
    <link href="~/libs/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet">
    <style>
        body {
            padding: 20px;
            background: #f5f5f5;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }

        .form-container {
            background: #fff;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            max-width: 800px;
            margin: 0 auto;
        }

        .page-title {
            font-size: 24px;
            font-weight: 600;
            color: #333;
            margin-bottom: 30px;
            text-align: center;
            padding-bottom: 15px;
            border-bottom: 2px solid #667eea;
        }

        .layui-form-item {
            margin-bottom: 20px;
        }

        .layui-form-label {
            width: 120px;
            font-weight: 500;
            color: #333;
        }

        .layui-input-block {
            margin-left: 140px;
        }

        .layui-input, .layui-select, .layui-textarea {
            border-radius: 6px;
            border: 1px solid #d9d9d9;
            transition: border-color 0.3s;
        }

            .layui-input:focus, .layui-select:focus, .layui-textarea:focus {
                border-color: #667eea !important;
                box-shadow: 0 0 8px rgba(102, 126, 234, 0.2) !important;
            }

        .layui-btn {
            border-radius: 6px;
            font-weight: 500;
            padding: 0 25px;
            height: 40px;
            line-height: 40px;
        }

        .layui-btn-normal {
            background: linear-gradient(135deg, #667eea, #764ba2);
            border: none;
        }

            .layui-btn-normal:hover {
                background: linear-gradient(135deg, #5a6fd8, #6a4190);
            }

        .form-actions {
            text-align: center;
            margin-top: 40px;
            padding-top: 20px;
            border-top: 1px solid #e6e6e6;
        }

        .required {
            color: #ff4757;
        }
    </style>
</head>
<body>
    <div class="form-container">
        <h2 class="page-title">
            <i class="layui-icon layui-icon-edit"></i>
            @(onboardingData != null ? "编辑入职审核" : "新增入职审核")
        </h2>

        <form class="layui-form" lay-filter="editForm">
            @if (onboardingData != null)
            {
                <input type="hidden" name="id" value="@onboardingData.Id">
            }

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required">*</span>人员名称</label>
                <div class="layui-input-block">
                    <input type="text" name="personName" required lay-verify="required"
                           placeholder="请输入人员名称" autocomplete="off" class="layui-input"
                           value="@(onboardingData?.PersonName ?? "")">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" lay-verify="phone"
                           placeholder="请输入联系电话" autocomplete="off" class="layui-input"
                           value="@(onboardingData?.Phone ?? "")">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="1" title="男" @(onboardingData?.Sex == 1 || onboardingData == null ? "checked" : "")>
                    <input type="radio" name="sex" value="2" title="女" @(onboardingData?.Sex == 2 ? "checked" : "")>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">定级</label>
                <div class="layui-input-block">
                    <select name="gradingMatch" lay-verify="">
                        <option value="">请选择定级</option>
                        <option value="P3" selected="@(onboardingData?.Level == "P3" ? "selected" : "")">P3</option>
                        <option value="P4" selected="@(onboardingData?.Level == "P4" ? "selected" : "")">P4</option>
                        <option value="P5" selected="@(onboardingData?.Level == "P5" ? "selected" : "")">P5</option>
                        <option value="P6" selected="@(onboardingData?.Level == "P6" ? "selected" : "")">P6</option>
                        <option value="P7" selected="@(onboardingData?.Level == "P7" ? "selected" : "")">P7</option>
                        <option value="P8" selected="@(onboardingData?.Level == "P8" ? "selected" : "")">P8</option>
                        <option value="P9" selected="@(onboardingData?.Level == "P9" ? "selected" : "")">P9</option>
                        <option value="P10" selected="@(onboardingData?.Level == "P10" ? "selected" : "")">P10</option>
                        <option value="P11" selected="@(onboardingData?.Level == "P11" ? "selected" : "")">P11</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">面试反馈</label>
                <div class="layui-input-block">
                    <textarea name="interviewFeedback" placeholder="请输入面试反馈"
                              class="layui-textarea">@(onboardingData?.FeedbackStatus ?? "")</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">面试结果</label>
                <div class="layui-input-block">
                    <select name="interviewResult" lay-verify="">
                        <option value="">请选择面试结果</option>
                        <option value="入职通过" selected="@(onboardingData?.ResultStatus == "入职通过" ? "selected" : "")">入职通过</option>
                        <option value="待定" selected="@(onboardingData?.ResultStatus == "待定" ? "selected" : "")">待定</option>
                        <option value="不通过" selected="@(onboardingData?.ResultStatus == "不通过" ? "selected" : "")">不通过</option>
                        <option value="需要复试" selected="@(onboardingData?.ResultStatus == "需要复试" ? "selected" : "")">需要复试</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">面试次数</label>
                <div class="layui-input-block">
                    <input type="number" name="interviewNumber" min="1" max="10"
                           placeholder="请输入面试次数" autocomplete="off" class="layui-input"
                           value="@(onboardingData?.InterviewCount ?? 1)">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">面试时间</label>
                <div class="layui-input-block">
                    <input type="text" name="interviewTime" id="interviewTime"
                           placeholder="请选择面试时间" autocomplete="off" class="layui-input"
                           value="@(onboardingData?.InterviewTime ?? "")">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">面试官</label>
                <div class="layui-input-block">
                    <input type="text" name="interviewPeople"
                           placeholder="请输入面试官姓名" autocomplete="off" class="layui-input"
                           value="@(onboardingData?.Interviewer ?? "")">
                </div>
            </div>

            <div class="form-actions">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitForm">
                    <i class="layui-icon layui-icon-ok"></i> 保存
                </button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeWindow()">
                    <i class="layui-icon layui-icon-close"></i> 取消
                </button>
            </div>
        </form>
    </div>

    <script src="~/libs/jquery/jquery.js"></script>
    <script src="~/libs/scripts/layui-v2.5.6/layui/layui.js"></script>
    <script>
        layui.use(['form', 'laydate', 'layer'], function() {
            var form = layui.form;
            var laydate = layui.laydate;
            var layer = layui.layer;

            // 初始化日期选择器
            laydate.render({
                elem: '#interviewTime',
                type: 'date',
                format: 'yyyy-MM-dd'
            });

            // 表单提交
            form.on('submit(submitForm)', function(data) {
                var field = data.field;
                var isEdit = !!field.id;

                // 数据验证
                if (!field.personName.trim()) {
                    layer.msg('请输入人员名称', { icon: 2 });
                    return false;
                }

                // 构建提交数据
                var submitData = {
                    personName: field.personName,
                    phone: field.phone || '',
                    sex: parseInt(field.sex) || 1,
                    gradingMatch: field.gradingMatch || '',
                    interviewFeedback: field.interviewFeedback || '',
                    interviewResult: field.interviewResult || '',
                    interviewNumber: parseInt(field.interviewNumber) || 1,
                    interviewTime: field.interviewTime ? new Date(field.interviewTime).toISOString() : new Date().toISOString(),
                    interviewPeople: field.interviewPeople || ''
                };

                if (isEdit) {
                    submitData.id = parseInt(field.id);
                }

                // 显示加载状态
                var loadIndex = layer.load(2, {
                    shade: [0.3, '#fff']
                });

                // 提交数据
                $.ajax({
                    url: isEdit ? '/HumanResources/UpdateOnboardingAudit' : '/HumanResources/CreateOnboardingAudit',
                    type: isEdit ? 'PUT' : 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify(submitData),
                    success: function(result) {
                        layer.close(loadIndex);
                        if (result.success) {
                            layer.msg(result.message, {
                                icon: 1,
                                time: 2000
                            }, function() {
                                // 关闭当前窗口并刷新父页面
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                        } else {
                            layer.msg(result.message, {
                                icon: 2,
                                time: 3000
                            });
                        }
                    },
                    error: function(xhr, status, error) {
                        layer.close(loadIndex);
                        layer.msg('操作失败，请稍后重试', {
                            icon: 2,
                            time: 3000
                        });
                    }
                });

                return false;
            });
        });

        // 关闭窗口
        function closeWindow() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
    </script>
</body>
</html> 